package com.swas.controller;

import com.swas.entity.BaseStatic;
import com.swas.entity.BaseSurvey;
import com.swas.service.BaseStaticService;
import com.swas.service.BaseSurveyService;
import com.swas.util.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/Property")
public class BaseDevicePropertyController {
    @Autowired
    private BaseStaticService StaticService;

    @Autowired
    private BaseSurveyService surveyService;

    @GetMapping("/getStaticAll")
    public ResultVO getStaticAll(Integer id) {
        List list = StaticService.getBaseStaicAll(id);
        List list1 = StaticService.getBaseSurveyAll(id);
        Map<String,List<Object>> map = new HashMap<>();
        map.put("sp",list);
        map.put("dp",list1);
        return ResultVO.success("ok",map);
    }

    @GetMapping("/getSurveyAll")
    public ResultVO getSurveyAll(Integer id) {
        List<BaseSurvey> list = surveyService.getBaseSurveyAll(id);
        return ResultVO.success("ok");
    }

    @PostMapping("/addStatic")
    public ResultVO addStatic(@RequestBody BaseStatic baseStatic) {
        boolean flag = StaticService.addStatic(baseStatic);
        if (flag) {
            return ResultVO.success("新增成功");
        } else {
            return ResultVO.fail("新增失败");
        }
    }


    @PostMapping("/addSurvey")
    public ResultVO addSurvey(@RequestBody BaseSurvey baseSurvey) {
        boolean flag = surveyService.addSurvey(baseSurvey);
        if (flag) {
            return ResultVO.success("新增成功");
        } else {
            return ResultVO.fail("新增失败");
        }
    }


    @PostMapping("/updateStatic")
    public ResultVO updateStatic(@RequestBody BaseStatic baseStatic) {
        boolean flag = StaticService.updataStatic(baseStatic);
        if (flag) {
            return ResultVO.success("修改成功");
        } else {
            return ResultVO.fail("修改失败");
        }
    }

    @PostMapping("/updateSurvey")
    public ResultVO updateSurvey(@RequestBody BaseSurvey baseSurvey) {
        boolean flag = surveyService.updateSurvey(baseSurvey);
        if (flag) {
            return ResultVO.success("修改成功");
        } else {
            return ResultVO.fail("修改失败");
        }
    }

    @DeleteMapping("/delStatic/{id}")
    public ResultVO delStatic(@PathVariable("id") Integer id){
        boolean flag = StaticService.delStatic(id);
        return ResultVO.success("删除成功");
    }

    @DeleteMapping("/delSurvey/{id}")
    public ResultVO delSurvey(@PathVariable("id") Integer id){
        boolean flag = surveyService.delSurvey(id);
        return ResultVO.success("删除成功");
    }
}